var MJson = function() {
    // json Key Name List
    this.msp = "msp";
    this.header = "header";
    this.client = "client";
    this.device = "device";
    this.params = "params";
    this.pub = "pub";
    this.parameter = "parameter";

    // client Key Name List
    MJson.CLIENT = function() {
    };
    MJson.CLIENT.USERID = "userid";
    MJson.CLIENT.USERCERTKEY = "userCertKey";

    // device Key Name List
    MJson.DEVICE = function() {
    };
    MJson.DEVICE.MODEL = "model";
    MJson.DEVICE.FIRMWARE = "firmware";
    MJson.DEVICE.PIN = "pin";
    MJson.DEVICE.IP = "ip";
    MJson.DEVICE.OID = "oid";
    MJson.DEVICE.SCREEN = "screen";
    MJson.DEVICE.DVID = "dvid";

    // pub Key Name List
    MJson.PUB = function() {
    };
    MJson.PUB.SID = "sid";
    MJson.PUB.SERVICENAME = "servicename";
    MJson.PUB.LISTCOUNT = "listcount";
    MJson.PUB.CURRPAGENO = "currpageno";
    MJson.PUB.JOINROOMSEQ = "joinRoomSeq";

    // parameter Key Name List
    MJson.PARAMETER = function() {
    };
    MJson.PARAMETER.NAME = "@name";
    MJson.PARAMETER.VALUE = "$";
    MJson.PARAMETER.BOOKINGTIME = "bookingTime";
    MJson.PARAMETER.BOOKINGDAY = "bookingTime";
    MJson.PARAMETER.NICKNAME = "nickName";
    MJson.PARAMETER.LOCATION = "location";
    MJson.PARAMETER.RESERVEST = "reserveSt";
    MJson.PARAMETER.RESERVEET = "reserveEt";
    MJson.PARAMETER.RESERVESEQ = "reserveSeq";
    MJson.PARAMETER.GOLFCLUBINFO = "golfClubInfo";
    MJson.PARAMETER.OPENYN = "openYn";
    MJson.PARAMETER.MENT = "ment";
    MJson.PARAMETER.LOCATION = "location";
    MJson.PARAMETER.RESERVEDATE = "reserveDate";
    //MJson.PARAMETER.BOOKINGTIME = "bookingTime"; // 존재
    MJson.PARAMETER.PASSWORD = "password";
    MJson.PARAMETER.PROCSTATUS = "procStatus";
    MJson.PARAMETER.ROUNDINGINFO = "roundingInfo";
    MJson.PARAMETER.HOLEINFO = "holeInfo";
    MJson.PARAMETER.INVITCNT = "invitCnt";
    MJson.PARAMETER.SEX = "sex";
    MJson.PARAMETER.AGE = "age";
    MJson.PARAMETER.AVERAGE = "aVerage";
    MJson.PARAMETER.SMOKEYN = "smokeYn";
    MJson.PARAMETER.JOINYN = "joinYn";
    MJson.PARAMETER.REGID = "regId";
    MJson.PARAMETER.BOOKUSERID = "bookUserId";
    MJson.PARAMETER.MODID = "modId";
    MJson.PARAMETER.RUSERNAME = "rUserName";
    MJson.PARAMETER.JOINROOMSEQ = "joinRoomSeq";
    MJson.PARAMETER.REPLYSEQ = "replySeq";
    MJson.PARAMETER.CONTENT = "content";
    MJson.PARAMETER.RESERVERDATE = "reserverDate";
    MJson.PARAMETER.PARTICIPANTID = "participantId";

    //로그
    MJson.PARAMETER.USERID = "userId";
    MJson.PARAMETER.PW = "pw";

    //회원가입
    MJson.PARAMETER.USERNAME="userName";
    MJson.PARAMETER.EMAIL = "email";
    MJson.PARAMETER.PHONENUM = "phonenum";
    MJson.PARAMETER.NICKNAME2 = "nickname";	//존재
    MJson.PARAMETER.USERTYPE = "userType";
    MJson.PARAMETER.SEX = "sex";
    MJson.PARAMETER.EMAILRECEIVEYN = "emailreceiveYn";
    MJson.PARAMETER.AUTHYN = "authYn";
    MJson.PARAMETER.USERLEVEL = "userLevel";

	//QnA 관련
    //MJson.PARAMETER.USERID = "userId";
	MJson.PARAMETER.QNATYPE="qna_type";
	MJson.PARAMETER.QNADETAILTYPE="qna_detail_type";
	MJson.PARAMETER.QNATITLE="title";
	MJson.PARAMETER.QNACONTENTS="contents";
	MJson.PARAMETER.QNASTATUS="status";
	
	//알림 관련
	MJson.PARAMETER.NOTIFICATIONTYPE = "notificationType";
	MJson.PARAMETER.PERIOD = "period";
	MJson.PARAMETER.TOPFLAG = "topFlag";
	MJson.PARAMETER.SERVICEGRP = "serviceGrp";
	MJson.PARAMETER.MESSAGEINSEQ = "messageInSeq";
	MJson.PARAMETER.MESSAGEOUTSEQ = "messageOutSeq";
	MJson.PARAMETER.INOUTFLAG = "inOutFlag";
	
    // Result Key Name List
    MJson.RESULTCODE = function() {
    };
    MJson.RESULTCODE.SUCCESS = "00000";
    
    

    // this.data = [];
    // this.data[this.msp] = [];

    this.clientItem = null;
    this.deviceItem = new Object();
    // device Default Data
    this.deviceItem.model = "PC";
    // this.deviceItem.ip = "192.168.0.1";
    this.deviceItem.ip = "localhost";

    this.pubItem = new Object();
    this.parameterItem = new Array();
};

MJson.prototype = {
    constructor : MJson,
    test : function(msg) {
        alert(msg);
    },
    putClient : function(key, value) {
        // device JSON Object Parameter 추가
        if(this.clientItem == null) {
            this.clientItem = new Object();
        }
        this.clientItem[key] = value;
        // alert("json str :: " + JSON.stringify(this.deviceItem));
    },
    putDevice : function(key, value) {
        // device JSON Object Parameter 추가
        this.deviceItem[key] = value;
        // alert("json str :: " + JSON.stringify(this.deviceItem));
    },
    putPub : function(key, value) {
        // pub JSON Object Parameter 추가
        this.pubItem[key] = value;
        // alert("json str :: " + JSON.stringify(this.pubItem));
    },
    putParameter : function(name, value) {
        // pub JSON Object Parameter 추가
        var item = new Object();

        item[MJson.PARAMETER.NAME] = name;
        item[MJson.PARAMETER.VALUE] = value;

        this.parameterItem.push(item);
        // alert("json str :: " + this.parameterItem.join(','));
    },
    getJsonString : function() {
        var result = new Object();

        result[this.msp] = new Object();
        if (JSON.stringify(this.deviceItem).length > 2) {
            // deviceItem에 저장되어 있는 데이터가 있을 경우
            result[this.msp][this.header] = new Object();
            console.log(this.clientItem);
            if(this.clientItem == null) {
                result[this.msp][this.header][this.client] = "";
            } else {
                result[this.msp][this.header][this.client] = this.clientItem;
            }
            
            result[this.msp][this.header][this.device] = this.deviceItem;
        }

        result[this.msp][this.params] = new Object();
        if (JSON.stringify(this.pubItem).length > 2) {
            result[this.msp][this.params][this.pub] = this.pubItem;
        }

        if (this.parameterItem.length > 0) {
            result[this.msp][this.params][this.parameter] = this.parameterItem;
        }
        // alert("result :: " + JSON.stringify(result));

        return JSON.stringify(result);
    },
    checkResult : function(json) {
        if (json.msp.result.code == MJson.RESULTCODE.SUCCESS) {
            return true;
        } else {
            return false;
        }
    },
    checkServiceResult : function(json) {
        if(!this.checkResult(json))
            return false;
            
        if (json.msp.contents.serviceResult == MJson.RESULTCODE.SUCCESS) {
            return true;
        } else {
            return false;
        }
    }
};

